<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="../common/header.jsp"%>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar">
        <div class="wu-toolbar-button">
            <%@include file="../common/menus.jsp"%>
        </div>
        <div class="wu-toolbar-search">
            <label>活动名称:</label><input id="search-name" class="wu-text" style="width:100px">
            <a href="#" id="search-btn" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="data-datagrid" class="easyui-datagrid" toolbar="#wu-toolbar"></table>
</div>
<!-- 修改窗口 -->
<div id="edit-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:550px; padding:10px;">
	<form id="edit-form" method="post">
        <input type="hidden" name="id" id="edit-id">
        <table>
          
            <tr>
                <td width="150" align="right">已有属于该活动商品数:</td>
                <td><input type="text" id="edit-now_num" name="now_num"  class="wu-text easyui-numberbox easyui-validatebox" data-options="required:true,min:1,precision:0, missingMessage:'请填写目前活动商品数'" /></td>
            </tr>
             <tr>
                <td width="150" align="right">该活动允许最大商品数:</td>
                <td><input type="text" id="edit-max_num" name="max_num"  class="wu-text easyui-numberbox easyui-validatebox" data-options="required:true,min:1,precision:0, missingMessage:'请填写最大活动商品数'" /></td>
            </tr>
             <tr>
                <td width="150" align="right">活动截止时间:</td>
                <td><input type="text" id="edit-time" name="action_time"  class="easyui-datetimebox" style="width:267.3px;"/></td>
            </tr>
          
        </table>
    </form>
</div>
<%@include file="../common/footer.jsp"%>

<!-- End of easyui-dialog -->
<script type="text/javascript">
	
/**
* Name 修改记录
*/
function edit(){
	var validate = $("#edit-form").form("validate");
	if(!validate){
		$.messager.alert("消息提醒","请检查你输入的数据!","warning");
		return;
	}
	var data = $("#edit-form").serialize();
	$.ajax({
		url:'edit_action',
		dataType:'json',
		type:'post',
		data:data,
		success:function(data){
			$("#data-datagrid").datagrid('clearSelections');
			if(data.type == 'success'){
				$.messager.alert('信息提示','修改成功！','info');
				$('#edit-dialog').dialog('close');
				$('#data-datagrid').datagrid('reload');
			}else{
				$.messager.alert('信息提示',data.msg,'warning');
			}
		}
	});
}

/**
* 打开修改窗口
*/
function openEdit(){
	//$('#edit-form').form('clear');
	var item = $('#data-datagrid').datagrid('getSelections');
	if(item == null || item.length == 0){
		$.messager.alert('信息提示','请选择要修改的数据！','info');
		return;
	}
	if(item.length > 1){
		$.messager.alert('信息提示','请选择一条数据进行修改！','info');
		return;
	}
	item = item[0];
	$('#edit-dialog').dialog({
		closed: false,
		modal:true,
        title: "修改用户信息",
        buttons: [{
            text: '确定',
            iconCls: 'icon-ok',
            handler: edit
        }, {
            text: '取消',
            iconCls: 'icon-cancel',
            handler: function () {
                $('#edit-dialog').dialog('close');                    
            }
        }],
        onBeforeOpen:function(){
        	$("#edit-id").val(item.id);
        	$('#edit-time').datetimebox('setValue', format(item.time));
        	$('#edit-max_num').numberbox('setValue',item.max_num);
        	$('#edit-now_num').numberbox('setValue',item.now_num);
        }
    });
}	
	
	

	
	
	
	//搜索按钮监听
	$("#search-btn").click(function(){
		
		var option = {name:$("#search-name").val()};
		
		$('#data-datagrid').datagrid('reload',option);
	});
	
	
	function add0(m){return m<10?'0'+m:m }
	function format(shijianchuo){
	//shijianchuo是整数，否则要parseInt转换
		var time = new Date(shijianchuo);
		var y = time.getFullYear();
		var m = time.getMonth()+1;
		var d = time.getDate();
		var h = time.getHours();
		var mm = time.getMinutes();
		var s = time.getSeconds();
		return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
	}
	
	
	/** 
	* 载入数据
	*/
	$('#data-datagrid').datagrid({
		url:'action',
		rownumbers:true,
		singleSelect:false,
		pageSize:20,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		idField:'id',
		fit:true,
		columns:[[
			{ field:'chk',checkbox:true},
			{ field:'name',title:'活动名称',width:60,align:'center'},
			{ field:'now_num',title:'已有属于该活动商品数',width:100,align:'center'},
			{ field:'max_num',title:'该活动允许最大商品数',width:100,align:'center'},
			{ field:'time',title:'活动截止时间',width:100,align:'center',formatter:function(value,row,index){
				if(value == null || "" == value)
				{
					return "";
				}else
				{
					return format(value);
				}
			}}
		]]
	});
</script>